package com.lm.service;

import com.lm.dao.UserMapper;
import com.lm.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    public List<User> getUserList() {
        return userMapper.getUserList();
    }

    public int insert(User user) {
        return userMapper.insert(user);
    }

    public User getUserById(int id) {
        return userMapper.getUserById(id);
    }

    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    public int deleteUser(int id) {
        return userMapper.deleteUser(id);
    }

    public User getUserByIdForMap(int id) {
        return userMapper.getUserByIdForMap(id);
    }

    public void testTransaction(User user) {
        userMapper.insert(user);
        //模拟异常
//        int i = 1/0;
        userMapper.deleteUser(user.getId());
    }
}
